package com.example.wm.SanWar.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.wm.SanWar.entity.Membershiproster;
import com.example.wm.SanWar.entity.MilitaryRecords;
import com.example.wm.SanWar.mapper.MilitaryRecordsMapper;
import com.example.wm.SanWar.service.MilitaryRecordsService;
import com.example.wm.common.Result;
import com.example.wm.common.ResultData;
import com.example.wm.utils.TsyUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/MilitaryRecords")
public class MilitaryRecordsController {
    @Resource
    private MilitaryRecordsMapper militaryRecordsMapper;
    @Resource
    private MilitaryRecordsService militaryRecordsService;
    @Resource
    private TsyUtils tsyUtils;
    @Transactional
    @PostMapping("/Insert")
    public Result Insert(@RequestBody MilitaryRecords militaryRecords) {

        Boolean b= militaryRecordsService.save(militaryRecords);
       return ResultData.success(b);
    }
    @Transactional
    @PostMapping("/update")
    public Result update(@RequestBody MilitaryRecords militaryRecords) {

        Boolean b= militaryRecordsService.updateById(militaryRecords);
        return ResultData.success(b);
    }

    @Transactional
    @PostMapping("/delete")
    public Result delete(@RequestBody MilitaryRecords militaryRecords) {

        Boolean b= militaryRecordsService.removeById(militaryRecords);
        return ResultData.success(b);
    }
    @Transactional
    @PostMapping("/find")
    public Result find(@RequestBody MilitaryRecords militaryRecords) {
    LambdaQueryWrapper<MilitaryRecords> lq=new LambdaQueryWrapper<>();
    lq.eq(MilitaryRecords::getRecordnameid,militaryRecords.getRecordnameid());
        List<MilitaryRecords> list=null;
    if(militaryRecords.getCurDate()!=null){
        lq.eq(MilitaryRecords::getCurDate,militaryRecords.getCurDate());
       list=militaryRecordsMapper.selectList(lq);


    }else {
       list=militaryRecordsMapper.selectList(lq);

    }


        return ResultData.success(list);
    }


}
